<?php

namespace spcj;

use other\Table;
use think\Db;
use think\db\Connection;
use think\Env;
use think\Exception;

class DbConn
{
    /**
     * @var Connection
     */
    private static $conn = null;

    /**
     * 数据库链接
     *
     * @return Connection|null
     * @throws Exception
     */
    static function getConn(): ?Connection
    {
        if (self::$conn === null){
            $conn = Env::get('spcj.type', 'mysql').'://'.
                Env::get('spcj.username', 'root'). ':'.
                Env::get('spcj.password', 'splineddhd1234!@#$').'@'.Env::get('spcj.hostname', '127.0.0.1').':3306/'.
                Env::get('spcj.database', 'zh') .'#utf8mb4';
            self::$conn = Db::connect($conn);
        }

        return self::$conn;
    }
}
